/*
 * Copyright 2013 Robert Peszek.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fun.curring

import fpig.util.curring.ExplicitCurring;


class ExpliciltyCurriedFunctionsPrototypeTests extends BaseCurriedFunctionsTests{

	def wayOfFun = new ExplicitCurring()

	Closure f(Closure c){
		wayOfFun.toFunction(c)
	}
	
	/**
	 * behavior the same as for auto-curring only explicit nested curried conversion is required.
	 */
	@Override
	void testOptionalParameters() {
		Closure c = {a , b=0-> f {c, d=0 -> a + b + c + d}} //explicit curried conversion required
		Closure fc = f c //same as CallUtil.toFunction(c)

		assert fc(1) instanceof Closure
		assert fc(1,2) instanceof Closure
		assert fc(1,2,3) instanceof Closure
		assert fc(1,2,3,4) == 10
		assert fc(1)(2) instanceof Closure
		assert fc(1)(2)(3) instanceof Closure
		assert fc(1)(2)(3)(4) == 10
	}

	@Override
	void testCallingCurriedFunction3() {
		Closure c = {a ,b -> f {c, d -> a + b + c + d}} //NOTE explicit nested curried conversion required for explicitCurring wayOfFun 
		Closure fc = f c //same as CallUtil.toFunction(c)

		assert c(1,2)(3,4) == 10
		
		assertFcCalls(fc)
	}
	
	@Override
	void testCallingCurriedFunction2() {
		Closure c = {a -> f {b, c, d -> a + b + c + d}} //NOTE explicit nested curried conversion required for explicitCurring wayOfFun 
		Closure fc = f c //same as CallUtil.toFunction(c)

		assert c(1)(2,3,4) == 10
		
		assertFcCalls(fc)
	}
	
	@Override
	void testCallingCurriedFunction4() {
		Closure c = {a -> f {b, c, d -> a + b + c + d}} //NOTE explicit nested curried conversion required for explicitCurring wayOfFun 
		Closure fc = f c //same as CallUtil.toFunction(c)

		assert c(1)(2,3,4) == 10
		
		assertFcCalls(fc)
	}


}
